'''

    Chantiers Report View. (global report)

'''

from django.http import HttpResponse
from django.shortcuts import render_to_response

import TasK.models as models

THEMESWITCH = False # Show the theme switcher widget ?
CAN_EDIT = True # Show links to admin ?

def _print_exc(func):
    '''
    Decorator to print the stack on exception
    '''
    def wrapped(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except:
            import traceback
            traceback.print_exc()
            raise

    return wrapped


def index(req):
    '''
    Default Chantier View.
    '''
    chantiers = models.Chantier.objects.all()
    return render_to_response(
        'reports/chantiers.html', 
        {
            'chantiers': chantiers,
            'THEMESWITCH':THEMESWITCH,
            'can_edit': req.GET.get('can_edit', CAN_EDIT),
        }
    )

@_print_exc
def render_functionalities(req, chantier_id):
    fonctionnalities = models.Fonctionalite.objects.filter(chantier__pk=chantier_id)
    return render_to_response(
        'reports/fonctionalites.html',
        {
            'fonctionalites': fonctionnalities, 
            'THEMESWITCH':THEMESWITCH,
            'can_edit': req.GET.get('can_edit', CAN_EDIT),
        }
    )
